//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Collections.ObjectModel;

namespace Microsoft.Research.ScientificWorkflow.ManagementStudioControls.WorkflowManagerModule
{
    /// <summary>
    /// The model which represents the Filter in the treeview of the left pane. 
    /// </summary>
    class WorkflowManagerFilterModel
    {
        /// <summary>
        /// The display name of the filter.
        /// </summary>
        private string filterDisplayName;

        /// <summary>
        /// The root filter of the filter.
        /// </summary>
        private string rootKey;

        /// <summary>
        /// The query string.
        /// </summary>
        private string filter;

        /// <summary>
        /// The children filters of the filter.
        /// </summary>
        private ObservableCollection<WorkflowManagerFilterModel> children;

        /// <summary>
        /// Flag to specify if the filter is selected by default.
        /// </summary>
        private bool isSelected;

        /// <summary>
        /// The model which represents the Filter in the treeview of the left pane.
        /// </summary>
        /// <param name="filterDisplayName">The name displayed.</param>
        /// <param name="rootKey">The root filter.</param>
        /// <param name="filter">The query filter</param>
        /// <param name="isSelected">Whether the treeview item is currently selected.</param>
        public WorkflowManagerFilterModel(string filterDisplayName, string rootKey, string filter, bool isSelected)
        {
            this.filterDisplayName = filterDisplayName;
            this.rootKey = rootKey;
            this.filter = filter;
            this.isSelected = isSelected;

            this.children = new ObservableCollection<WorkflowManagerFilterModel>();
        }

        /// <summary>
        /// The display name of the filter.
        /// </summary>
        public string FilterDisplayName
        {
            get
            {
                return this.filterDisplayName;
            }
            set
            {
                this.filterDisplayName = value;
            }
        }

        /// <summary>
        /// The root filter of the filter.
        /// </summary>
        public string RootKey
        {
            get { return rootKey; }
        }

        /// <summary>
        /// The query string.
        /// </summary>
        public string Filter
        {
            get { return filter; }
        }

        /// <summary>
        /// The children filters of the filter.
        /// </summary>
        public ObservableCollection<WorkflowManagerFilterModel> Children
        {
            get { return children; }
        }

        /// <summary>
        ///  Flag to specify if the filter is selected by default.
        /// </summary>
        public bool IsSelected
        {
            get
            {
                return isSelected;
            }
        }

        /// <summary>
        /// Override the base ToString method. Helps provide automation IDs for the treeview items.
        /// </summary>
        /// <returns>The string representation of the object.</returns>
        public override string ToString()
        {
            if (string.IsNullOrEmpty(this.filterDisplayName))
            {
                return base.ToString();
            }
            return this.filterDisplayName;
        }
    }
}
